package com.kingwood.algorithm.test200;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

// 符号运算
// https://fcqian.blog.csdn.net/article/details/135005092
public class FuHaoYunSuan {

    static class Fractions {
        int ch; // 分子
        int fa; // 分母
        public Fractions() {
        }

        public Fractions(int fa, int ch) {
            this.fa = fa;
            this.ch = ch;
        }
    }

    static LinkedList<Fractions> oper_num = new LinkedList<>();
    static LinkedList<Character> oper_sign = new LinkedList<>();

    public static String getResult(String str) {
        char[] charArr = str.toCharArray();
        // System.out.println(Arrays.toString(charArr));
        int len = charArr.length;
        StringBuilder sb = new StringBuilder();
        HashMap<Character, Integer> priority = new HashMap<>();
        priority.put('+', 1);
        priority.put('-', 1);
        priority.put('*', 2);
        priority.put('/', 2);

        for (int i=0; i<len; i++) {
            char c = charArr[i];
            if (c >= '0' && c<='9') {
                while (c >= '0' && c<='9') {
                    sb.append(c);
                    if (i+1 >= len) {
                        break;
                    }

                    i++;
                    c = charArr[i];
                }

                Fractions fractions = new Fractions(1, Integer.parseInt(sb.toString()));
                oper_num.addLast(fractions);
                sb = new StringBuilder();
            }

            if (c == '+' || c == '-' || c == '*' || c == '/') {
                while (oper_sign.size() > 0 && oper_sign.getLast() != '(' &&
                        priority.get(oper_sign.getLast()) >= priority.get(c)) {
                    calc();
                }
                oper_sign.addLast(c);
            }  else if (c == ')') {
                // 计算答案
                while (oper_sign.getLast() != '(') {
                    calc();
                }
                // 删除最后一个字符 (
                oper_sign.removeLast();
            } else if (c == '('){
                // (
                oper_sign.addLast(c);
            }
        }

        // 栈中还有两个以上的数
        while (oper_num.size() > 1) {
            calc();
        }

        Fractions result = oper_num.getLast();
        if (result.fa == 0) {
            return "ERROR";
        }

        // 求分子分母的最大公约数，并约分
        int k = getMaxCommonDivisor(result.fa, result.ch);
        result.fa /= k;
        result.ch /= k;

        String sign = (result.fa > 0 && result.ch < 0) || (result.fa < 0 && result.ch > 0) ? "-" : "";
        int fa = Math.abs(result.fa);
        int ch = Math.abs(result.ch);

        String ans = "";
        if (fa == 1) {
            ans = sign + ch;
        } else {
            ans = sign + ch + "/" + fa;
        }

        return ans;
    }

    // 计算栈中的元素
    public static void calc() {
        Fractions b = oper_num.removeLast();
        Fractions a = oper_num.removeLast();

        char op = oper_sign.removeLast();
        Fractions result = new Fractions();

        switch (op) {
            case '+':
                result.fa = a.fa * b.fa;
                result.ch = a.ch * b.fa + b.ch * a.fa;
                break;
            case '-':
                result.fa = a.fa * b.fa;
                result.ch = a.ch * b.fa - b.ch * a.fa;
                break;
            case '*':
                result.fa = a.fa * b.fa;
                result.ch = a.ch * b.ch;
                break;
            case '/':
                result.fa = a.fa * b.ch;
                result.ch = a.ch * b.fa;
                break;
        }

        oper_num.add(result);
    }

    // 求最大公约数 10, 20
    public static int getMaxCommonDivisor(int x, int y) {
        while (y != 0) {
            int tmp = y;
            y = x % y;
            x = tmp;
        }

        return x;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine().replaceAll(" ", "");
        String res = getResult(str);
        System.out.println(res);

//        System.out.println(getMaxCommonDivisor(10, 20));
    }


}
